﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yunwei.Core.Permission
{
    /// <summary>
	/// 设置权限名称、是否验证、是否在列表中显示等。
	/// </summary>
    [AttributeUsage(AttributeTargets.All)]
    public class ActionPermissionAttribute : Attribute
    {
        /// <summary>
        /// 列表默认显示顺序
        /// </summary>
        public int ShowIndex = 100;

        private bool _showInList = true;

        /// <summary>
        /// 权限列表中的描述字段
        /// </summary>
        public string Description
        {
            get;
            set;
        }

        /// <summary>
        /// 是否可以匿名访问（用于登录等页面）
        /// </summary>
        public bool AllowAnonymous
        {
            get;
            set;
        }

        /// <summary>
        /// 是否在列表中显示（可以匿名访问的默认都是不在列表中显示的）
        /// </summary>
        public bool AdminOnly
        {
            get;
            set;
        }

        /// <summary>
        /// 分组名称
        /// </summary>
        public string GroupName
        {
            get;
            set;
        }

        /// <summary>
        /// 是否在列表中显示（匿名访问和管理页面都不在列表显示）
        /// </summary>
        public bool ShowInList
        {
            get
            {
                return !this.AdminOnly && !this.AllowAnonymous && this._showInList;
            }
            set
            {
                this._showInList = value;
            }
        }

        /// <summary>
        /// Action访问权限
        /// </summary>
        public ActionPermissionAttribute()
        {
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="des">权限的描述</param>
        public ActionPermissionAttribute(string des)
        {
            this.Description = des;
        }

        /// <summary>
        /// 允许匿名访问
        /// </summary>
        /// <param name="allowAnonymous"></param>
        public ActionPermissionAttribute(bool allowAnonymous)
        {
            this.AllowAnonymous = allowAnonymous;
        }
    }
}
